function detailData(result) {
    const data = JSON.parse(result.data) !== null ? JSON.parse(result.data) : null;
    if (result.stationId === stationId) {
        if (WS_CMD.STATE === result.cmd) {
            ws_setInfo(data)
            refreshContr()
            return false;
        } else if (WS_CMD.MODE_CHANGE === result.cmd) {
            ws_setMode(data)
            refreshContr()
            return false;
        } else if (WS_CMD.CONF === result.cmd) {
            ws_setTasks()
            return false;
        } else if (WS_CMD.FEED_REPORT === result.cmd) {
            ws_setFeedList()
            return false;
        } else if (WS_CMD.STOP_STATUS === result.cmd) {
            ws_setStopStatus(data)
            refreshContr();
            return false;
        } else if (WS_CMD.STATION_STATUS === result.cmd) {
            ws_setLineStatus(data)
            return false;
        }
    }
}

//Websocket下 自动修改 运行状态 工作模式 饲料报警状态 温度
function ws_setInfo(data) {
    ws_setStopStatus(data);

    var bait_warningDom = $("#bait_warning");
    if (data.baitStatus === 0) {
        bait_warningDom.html('有料');
        bait_warningDom.addClass('label-primary')
    } else if (data.baitStatus === 1) {
        bait_warningDom.html('无料');
        bait_warningDom.addClass('label-danger')
    }

    var airTemp = data.airTemp;
    var waterTemp = data.waterTemp;
    if (waterTemp < 0 || waterTemp > 35) {
        waterTemp = -100;
    }
    if (airTemp < -10 || airTemp > 35) {
        airTemp = -100;
    }
    if (waterTemp === -100 && airTemp === -100) {
        $("#tempValueStyle").hide()
    } else {
        if (waterTemp === -100) {
            $("#waterTempValue").html("##");
        } else {
            $("#waterTempValue").html(waterTemp.toFixed(1));
        }
        if (airTemp === -100) {
            $("#airTempValue").html("##");
        } else {
            $("#airTempValue").html(airTemp.toFixed(1));
        }
        if (waterTemp === -100) {
            $("#yincang").hide()
            $("#yincang1").show()
            $("#airTemp").addClass("tempChoose");
            $("#waterTemp").removeClass("tempChoose");
            updateTempTypeFunction(1);
        } else {
            $("#yincang").show()
            $("#yincang1").hide()
            $("#airTemp").removeClass("tempChoose");
            $("#waterTemp").addClass("tempChoose");
            updateTempTypeFunction(0);
        }
    }
    ws_setMode(data.workMode);
}

function updateTempTypeFunction(tempType) {
    Request.builder()
        .url(STATION_UPDATE_TYPE + "/" + stationId)
        .data({"tempType": tempType})
        .isToken(true)
        .callback(function (e) {
            if (e.code === "00000") {

            } else {
                LayerUtil.failMsg(e.msg != null ? e.msg : ERROR_MSG.FAIL)
            }
        }).post();
}

//Websocket下 自动修改 设备模式相关
function ws_setMode(data) {
    var mode = data.mode;
    setStationStatusMode(mode)
    var modeInfoDom = $("#mode");
    var modeDom = $("#statusinfomode");
    if (mode === 2) {
        modeInfoDom.removeClass('label-danger')
        modeInfoDom.removeClass('label-primary')
        modeDom.removeClass('label-danger')
        modeDom.removeClass('label-primary')
        $("#zidongspan").html(' ')
        $("#shoudongspan").html(' ')
    } else if (mode === 1) {
        modeInfoDom.removeClass('label-danger')
        modeInfoDom.removeClass('label-debug')
        modeDom.removeClass('label-danger')
        modeDom.removeClass('label-debug')
        $("#tiaoshispan").html(' ')
        $("#shoudongspan").html(' ')
    } else {
        modeInfoDom.removeClass('label-primary')
        modeInfoDom.removeClass('label-debug')
        modeDom.removeClass('label-primary')
        modeDom.removeClass('label-debug')
        $("#tiaoshispan").html(' ')
        $("#zidongspan").html(' ')
    }
}

//Websocket下 自动修改 设置任务的列表
function ws_setTasks() {
    Request.builder()
        .url(STATION_DETAIL + "/" + stationId)
        .isToken(true)
        .callback(function (e) {
            if (e.code === "00000") {
                var data = e.data;
                setTask(data);
                $("#freesecs").attr("nsecs", data.normalSecs);
                $("#freesecs").attr("hsecs", data.highSecs);
            } else if (e.code === "C0013") {
                LayerUtil.failMsg(e.msg != null ? e.msg : ERROR_MSG.FAIL)
                setTimeout(function () {
                    window.location.href = "/admin/station/index.html";
                }, 1000)
            }
        }).get();
    refreshMonthProducts();
}

//Websocket下 自动修改 设置任务的列表
function ws_setFeedList() {
    Request.builder()
        .url(STAION_FEED_RECORD_DAY_LIST + "?stationId=" + stationId)
        .isToken(true)
        .callback(function (e) {
            if (e.code === "00000") {
                var data = e.data;
                var resultData = {};
                resultData.total = data.recordCount;
                resultData.rows = data.resultData;
                $('.feedDay').bootstrapTable('refresh', resultData);
            } else {
                LayerUtil.failMsg(e.msg != null ? e.msg : ERROR_MSG.FAIL)
            }
        }).get();
    refreshMonthProducts();
}

function refreshMonthProducts() {
    Request.builder()
        .url(STAION_PRODUCE_RECORD_LIST + "?stationId=" + stationId)
        .isToken(true)
        .callback(function (e) {
            if (e.code === "00000") {
                var data = e.data;
                var resultData = {};
                resultData.total = data.recordCount;
                resultData.rows = data.resultData;
                $('.monthProducts').bootstrapTable('refresh', resultData);
            } else {
                LayerUtil.failMsg(e.msg != null ? e.msg : ERROR_MSG.FAIL)
            }
        }).get();
    refreshContr();
}

function refreshContr() {
    Request.builder()
        .url(STAION_CONTROL_RECORD_LIST + "?stationId=" + stationId)
        .isToken(true)
        .callback(function (e) {
            if (e.code === "00000") {
                var data = e.data;
                var resultData = {};
                resultData.total = data.recordCount;
                resultData.rows = data.resultData;
                $('.contr').bootstrapTable('refresh', resultData);
            } else {
                LayerUtil.failMsg(e.msg != null ? e.msg : ERROR_MSG.FAIL)
            }
        }).get();
}

function ws_setStopStatus(data) {
    var stopStatus = data.stopStatus;
    var runStatesDom = $("#runStates");
    if (stopStatus === 0) {
        runStatesDom.html('运行');
        runStatesDom.addClass('label-primary')
        runStatesDom.removeClass('label-danger')
    } else if (stopStatus === 1) {
        runStatesDom.html('停止');
        runStatesDom.removeClass('label-primary')
        runStatesDom.addClass('label-danger')
    }
}


//Websocket下 自动修改 运行状态 工作模式 饲料报警状态 温度
function ws_setLineStatus(data) {
    if (data.status === 0) {
        $("#status").html('<i class="fa fa-circle text-info pr-1"></i>在线');
    } else {
        $("#status").html('<i class="fa fa-circle text-muted pr-1"></i>离线');
    }
}